// 该方法使用控制页面只有创建一个div
var CreateDiv = (function() {
    var instance;

    var CreateDiv =function(html) {
        if(instance) {
            return instance;
        }
        this.html = html;
        this.init();
        return instance = this;
    }

    CreateDiv.prototype.init = function() {
        var div = document.createElement('div');
        div.innerHTML = this.html;
        document.body.appendChild(div);
    }

    return CreateDiv;
})();

var a = new CreateDiv('xiaoming');
var b = new CreateDiv('xiaohong');

alert(a===b);

// 这种方式为了将返回的实例封装起来 使用了自执行匿名函数和闭包 

